<?
	require_once('init.php');
	require_once('dataModel.php');
	if(!$_GET['sort1id'])
	{
		$sort1id = 0;
	}
	else
	{
		$sort1id = $_GET['sort1id'];
	}

	if(!$_GET['sort2id'])
	{
		$sort2id = 0;
	}
	else
	{
		$sort2id = $_GET['sort2id'];
	}
	
	if(!$_GET['colorid'])
	{
		$colorid = 0;
	}
	else
	{
		$colorid = $_GET['colorid'];
	}	
	
	if(!$_GET['orderby'])
	{
		$orderby = "sortby1";
	}
	else
	{
		$orderby = $_GET['orderby'];
	}	
		
	$sql = "select COUNT(*) as RowNum from goods ";
	$sql.= "where 1=1 ";
	if($sort1id !=0)
	{
		$sql.= "and sort1id='".$sort1id."' ";
	}

	if($sort2id !=0)
	{
		$sql.= "and sort2id='".$sort2id."' ";
	}

	if($colorid !=0)
	{
		$sql.= "and colorid='".$colorid."' ";
	}


	$sql.= "limit 0,1";
	 
	$db = MySQL::getInstance('','r-w'); 
	$result = $db->fetch($db->query($sql));
    $rs_count=$result["RowNum"];

	if(!$_GET['pgno'])
	{
		$PageNo = 1;
	}
	else
	{
		$PageNo = $_GET['pgno'];
	}

	$total_showpages = 100; 
	$num_perpage = 12;   

	$from = ($PageNo-1)*$num_perpage;	
	$total_pages = ceil($rs_count / $num_perpage); 
	
	if($total_pages>=$PageNo+$total_showpages)
	{
		$start = $PageNo;
		$stop = $PageNo+$total_showpages-1;
	}
	elseif($total_pages < $PageNo+$total_showpages)
	{
		if($total_pages>$total_showpages)
		{
			$start = $total_pages-$total_showpages+1;
			$stop = $total_pages;		
		}
		else
		{
			$start = 1;
			$stop = $total_pages;
		}
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
	<meta http-equiv="Content-Type" content="text/html; charset=<?=$lng_characset;?>" />
	<meta name="keywords" content="GreenCity,Shoes,Ь,��Ь,ŮЬ,����" />
	<meta name="description" content="GreenCity" />
	<meta name="copyright" content="Copyright (c) 2011 www.GreenCity.com All Rights Reserved." />
	<meta name="publisher" content="Copyright (c) 2010 www.GreenCity.com All Rights Reserved." />
	<meta name="author" content="GreenCity Team" />
	
	<TITLE><?=$AllPageTitle;?></TITLE> 

	<link href="css/main.css" rel="stylesheet" type="text/css" />
	<link href="css/Buttonstyle.css" rel="stylesheet" type="text/css" />
	<link href="css/jquery.hiAlerts.css" rel="stylesheet" type="text/css" />
	<link href="css/body2.css" rel="stylesheet" type="text/css" />

	<? include("alljs.php"); ?>

	<script language="javascript">
   		function ChangeColor(CID)
   		{
            location="body2.php?sort1id="+ <?=$sort1id;?>+"&sort2id="+ <?=$sort2id;?>+"&orderby="+ <?=$orderby;?>+"&colorid="+CID;
		}    

   		function ChangeSort(SID)
   		{
            location="body2.php?sort1id="+ <?=$sort1id;?>+"&sort2id="+ <?=$sort2id;?>+"&colorid="+<?=$colorid;?>+"&orderby="+SID;
		}    
	</script>

	 
</head>
	<body>	
		<?
		include("header.php"); 
		?>

		<div id="body2_all" >
			<div id="body2_h01" ></div>
			
			<div class="body2_div">
			
				<div class="body2_a01">
					<!--����-->
					<?
					if ($sort1id=='0')
					{
					?>
						<div class="body2_a02"><b><?=$strAll;?></b></div>
					<?	
					}
					else
					{
						$strSQL= "select id,". $strLanguage_Sort1 ." from sort1 where delflag<>'1' and id='". $sort1id ."' limit 0,1";  
						$db = MySQL::getInstance('','r-w'); 
						$DBR=$db->query($strSQL); 
					  	$resort1=$db->fetch($DBR);
					  	
  				    ?>
						<div class="body2_a02"><b><?=$resort1["sort1name"];?></b></div>
					<?
					}
					?>	
					<!--����-->

					<!--���1-->
					<div class="body2_a03"><b><?=$strSortName;?></b></div>
					<div class="body2_a04"><a href="body2.php?sort1id=0"><?=$strAll;?></a></div>

					<?
					$strSQL= "select id,". $strLanguage_Sort1 ." from sort1 where delflag<>'1' order by id ";  
					$db = MySQL::getInstance('','r-w'); 
					$DBR=$db->query($strSQL); 
					
			      	while($resort1=$db->fetch($DBR))
			    	{
			    	?>
					    <div class="body2_a04"><a href="body2.php?sort1id=<?=$resort1["id"];?>"><?=$resort1["sort1name"];?></a></div>
					<?
					}
					?>		
					<!--���1-->

					<div class="body2_a03"></div>

					<!--���2-->
					<div class="body2_a03"><b><?=$strSortName1;?></b></div>
					<div class="body2_a04"><a href="body2.php?sort1id=<?=$sort1id;?>&sort2id=0"><?=$strAll;?></a></div>

					<?
					$strSQL= "select id,". $strLanguage_Sort2 ." from sort2 where delflag<>'1' order by id ";  
					$db = MySQL::getInstance('','r-w'); 
					$DBR=$db->query($strSQL); 
					
			      	while($resort1=$db->fetch($DBR))
			    	{
			    	?>
					    <div class="body2_a04"><a href="body2.php?sort1id=<?=$sort1id;?>&sort2id=<?=$resort1["id"];?>"><?=$resort1["sort2name"];?></a></div>
					<?
					}
					?>		
					<!--���2-->
		

					<!--��ɫ-->
					<div class="body2_a03"></div>
					<div class="body2_a03"><b><?=$strColorName;?></b></div>
					<div id=pcolorname class="body2_a06">
						<select name="colorname" id="colorname" onchange="ChangeColor(this.value);">
							<option value="0" selected="selected"><?=$strAll;?></option>
						<?
							$strSQL= "select id,". $strLanguage_Color ." from color where delflag<>'1' order by id ";  
							$db = MySQL::getInstance('','r-w'); 
							$DBR=$db->query($strSQL); 
							
					      	while($rscolor=$db->fetch($DBR))
					    	{
					    	?>
								<option <?=$colorid==$rscolor["id"]?"selected":"";?> value="<?=$rscolor["id"];?>"><?=$rscolor["colorname"];?></option>
							<?
							}
						?>
						</select>
					</div>
		        </div>

				<div class="body2_a01" style="width:720px;">
					<div class="body2_a05" style="padding-top:20px;">
						<div id=psortby class="body2_a06">
							<select name="sortby" id="sortby" onchange="ChangeSort(this.value);">
								<option value="sortby1" selected="selected"><?=$sortby1;?></option>
								<option value="sortby2" <?=$orderby=="sortby2"?"selected":"";?>><?=$sortby2;?></option>
								<option value="sortby3" <?=$orderby=="sortby3"?"selected":"";?>><?=$sortby3;?></option>
								<option value="sortby4" <?=$orderby=="sortby4"?"selected":"";?>><?=$sortby4;?></option>
							</select>
						</div>

						<!--���2-->
						<?
						$strSQL= "select id,". $strLanguage_Sort2 ." from sort2 where delflag<>'1' order by id desc";  
						$db = MySQL::getInstance('','r-w'); 
						$DBR=$db->query($strSQL); 
						
				      	while($resort1=$db->fetch($DBR))
				    	{
				    	?>
						    <div class="body2_a07"><a href="body2.php?sort1id=<?=$sort1id;?>&sort2id=<?=$resort1["id"];?>"><?=$resort1["sort2name"];?></a></div>
						<?
						}
						?>		

						<div class="body2_a07"><a href="body2.php?sort1id=<?=$sort1id;?>&sort2id=0"><?=$strAll;?></a></div>
						<!--���2-->

					</div>

					<div class="body2_a05" style="height:20px;padding-top:10px;text-align:right;">
						<div class="body2_a05" style="float:right;height:20px;width:15px;"></div>
						<!-- ��ʾ ҳ��-->
						<?
						if($PageNo>1)
						{ 
							$npage = $PageNo-1;  /*��һҳ*/
						?>
							<span><a class="paging_page" href="body2.php?sort1id=<?=$sort1id;?>&sort2id=<?=$sort2id;?>&pgno=<?=$npage;?>"><</a></span>
						<?
						}
						
						for($i=$start;$i<=$stop;$i++)
						{
							if($i==$PageNo)
							{
						?>
							<span class="paging_page"><?=$i?></span>
						<?
						 	}
							else
							{
						?>	
							<span class="paging_page"><a href="body2.php?sort1id=<?=$sort1id;?>&sort2id=<?=$sort2id;?>&pgno=<?=$i;?>"><?=$i;?></a></span>
						<?	
							}  
						}
						
					   	if($PageNo < $total_pages)
					   	{
					   		$npage = $PageNo+1;   /*��ҳ*/
					  	?>   
					  		<span class="paging_page"><a href="body2.php?sort1id=<?=$sort1id;?>&sort2id=<?=$sort2id;?>&pgno=<?=$npage;?>">></a></span> 
					  	<? 
					  	}
					  	?>
                	</div> 

					<div class="body2_a05" style="height:440px;">
						<?
					    /*��ʾ��ƷͼƬ*/
						$sql = "select id,adviceprice,pic1,". $strLanguage_Goods ." from goods ";
						$sql.= "where 1=1 ";
						if($sort1id !=0)
						{
							$sql.= "and sort1id='".$sort1id."' ";
						}
					
						if($sort2id !=0)
						{
							$sql.= "and sort2id='".$sort2id."' ";
						}
					
						if($colorid !=0)
						{
							$sql.= "and colorid='".$colorid."' ";
						}

						if($orderby=='sortby1')
						{
							$sql.= "order by id limit ".$from.",".$num_perpage."";
						}
						elseif($orderby=='sortby2')
						{
							$sql.= "order by goodsid limit ".$from.",".$num_perpage."";
						}
						elseif($orderby=='sortby3')
						{
							$sql.= "order by adviceprice limit ".$from.",".$num_perpage."";
						}
						elseif($orderby=='sortby4')
						{
							$sql.= "order by adviceprice desc limit ".$from.",".$num_perpage."";
						}
						 
						
						$db = MySQL::getInstance('','r-w'); 
						$DBR=$db->query($sql); 
				      	while($rsgoods=$db->fetch($DBR))
				    	{
						?>
							<div class="body2_a08">        <!-- ͼƬ��С150*100 -->
								<a href="goodsdetail.php?GID=<?=$rsgoods["id"];?>"><img class="body2_a09" src="<?=$lng_picpath;?><?=$rsgoods["pic1"];?>" border="0" /></a>
                                <div class="body2_a10"><a href="goodsdetail.php?GID=<?=$rsgoods["id"];?>"><b><?=$rsgoods["goodsname"];?> | $<?=$rsgoods["adviceprice"];?></b></a></div>
							</div>
						<?
					
						}

					    /*��ʾ��ƷͼƬ*/
				        ?>
				    </div>

					<div class="body2_a05" style="height:20px;padding-top:10px;text-align:right;">
						<div class="body2_a05" style="float:right;height:20px;width:15px;"></div>
						<!-- ��ʾ ҳ��-->
						<?
						if($PageNo>1)
						{ 
							$npage = $PageNo-1;  /*��һҳ*/
						?>
							<span><a class="paging_page" href="body2.php?sort1id=<?=$sort1id;?>&sort2id=<?=$sort2id;?>&pgno=<?=$npage;?>"><</a></span>
						<?
						}
						
						for($i=$start;$i<=$stop;$i++)
						{
							if($i==$PageNo)
							{
						?>
							<span class="paging_page"><?=$i?></span>
						<?
						 	}
							else
							{
						?>	
							<span class="paging_page"><a href="body2.php?sort1id=<?=$sort1id;?>&sort2id=<?=$sort2id;?>&pgno=<?=$i;?>"><?=$i;?></a></span>
						<?	
							}  
						}
						
					   	if($PageNo < $total_pages)
					   	{
					   		$npage = $PageNo+1;   
					  	?>   
					  		<span class="paging_page"><a href="body2.php?sort1id=<?=$sort1id;?>&sort2id=<?=$sort2id;?>&pgno=<?=$npage;?>">></a></span> 
					  	<? 
					  	}
					  	?>
                	</div> 

		        </div>
		        
			</div>

			<div id="body2_h02" ></div>
		</div>


		<?
		include("footer.php"); 
		?>
	</body>		
</html>